const bannerModel = require("../../db/models")["banner"];
const responseCode = require("../../config/httpCode");
const { Op } = require("sequelize");
const router = require("koa-router")({
  prefix: "/auth/banner"
});

router.get("/", async ctx => {
  const banner = await bannerModel.findAll();
  ctx.body = {
    code: 200,
    data: banner
  };
});

router.post("/", async ctx => {
  const b = ctx.request.body;
  const banner = await bannerModel.create(b);
  ctx.body = {
    code: 200,
    data: banner
  };
});

router.delete("/:id", async ctx => {
  const id = ctx.params.id;
  const banner = await bannerModel.destroy({ where: { id } });
  ctx.body = {
    code: 200,
    data: banner
  };
});
module.exports = router;
